package cate.game.gm;

import cate.game.framework.ModuleMan;
import cate.game.gm.sub.GmActorRun;
import cate.game.gm.sub.GmBanRun;
import cate.game.gm.sub.GmRoleRenameRun;
import cate.game.gm.sub.KfRebateRun;
import cate.game.res.guild.GuildForGm;
import cate.game.gm.sub.BagForGm;
import cate.game.gm.sub.VipRebateForGm;
import cp.solution.business.game.bag.BagDeductCmd;
import cp.solution.business.game.guild.GuildModifyCmd;
import cp.solution.business.gm.ActorEntity;
import cp.solution.business.gm.ActorLvLog;
import cp.solution.business.gm.ActorSetLog;
import cp.solution.business.gm.GmBanEntity;
import cp.solution.business.gm.cmd.GmTempCmd;
import cp.solution.business.gm.dto.ActorNoteCmd;
import cp.solution.business.gm.dto.ActorPayCmd;
import cp.solution.business.gm.dto.VipRebateCmd;
import cp.solution.pattern.Feedback;
import cp.solution.rpc.RpcMsgHead;
import cp.solution.rpc.path.RpcGmPath;
import cp.solution.rpc.path.RpcSharePath;
import easy.java.struct.MapBox;

public class GmManager extends ModuleMan {

    @Override
    public void initDependent() throws Exception {
        game.rpcRecv().onRequestResponseTemplate(RpcGmPath.TEMP_CMD_C2G, GmTempCmd.class, this::tempCmdHandler);
        game.rpcRecv().onRequestResponseTemplate(RpcGmPath.GUILD_LIST_REQ, void.class,
                (head, input) -> GuildForGm.getList(game));
        game.rpcRecv().onRequestResponseTemplate(RpcGmPath.GUILD_MODIFY_CMD, GuildModifyCmd.class,
                (head, input) -> GuildForGm.modify(game, input));
        game.rpcRecv().onRequestResponseTemplate(RpcGmPath.ROLE_BAG_VIEW, String.class,
                (head, input) -> BagForGm.doView(game, input));
        game.rpcRecv().onRequestResponseTemplate(RpcGmPath.ROLE_BAG_DEDUCT, BagDeductCmd.class,
                (head, input) -> BagForGm.doDeduct(game, input));
        game.rpcRecv().onRequestResponseTemplate(RpcGmPath.BAN_C2G, GmBanEntity.class,
                (head, input) -> GmBanRun.run(game, input));

        game.rpcRecv().onRequestResponseTemplate(RpcSharePath.VIP_REBATE_CMD, VipRebateCmd.class,
                (head, input) -> VipRebateForGm.exe(game, input));
        game.rpcRecv().onRequestResponseTemplate(RpcGmPath.KF_REBATE_C2G, MapBox.class,
                (head, input) -> KfRebateRun.exe(game, input));

        game.rpcRecv().onRequestResponseTemplate(RpcGmPath.ACTOR_SET_C2G, ActorSetLog.class,
                (head, input) -> GmActorRun.set(game, input));
        game.rpcRecv().onRequestResponseTemplate(RpcGmPath.ACTOR_PAY_C2G, ActorPayCmd.class,
                (head, input) -> GmActorRun.pay(game, input));
        game.rpcRecv().onRequestResponseTemplate(RpcGmPath.ACTOR_LV_C2G, ActorLvLog.class,
                (head, input) -> GmActorRun.lv(game, input));
        game.rpcRecv().onRequestResponseTemplate(RpcGmPath.ACTOR_NOTE_C2G, ActorNoteCmd.class,
                (head, input) -> GmActorRun.note(game, input));
        game.rpcRecv().onRequestResponseTemplate(RpcGmPath.ACTOR_WRITE_C2G, ActorEntity.class,
                (head, input) -> GmActorRun.write(game, input));
    }

    private Feedback tempCmdHandler(RpcMsgHead head, GmTempCmd cmd) {
        Feedback feedback = new Feedback().start();
        try {
            switch (cmd.action) {
                case GmTempCmd.ACTION_ECHO:
                    feedback.text("新美食("+game.config.gs.introduction()+")响应了你");
                    break;
                case GmTempCmd.ACTION_ROLE_RENAME:
                    feedback.text(GmRoleRenameRun.run(game, cmd));
                    break;
                default:
                    feedback.text("新美食还不支持 "+cmd.action+" 这个操作");
                    break;
            }
        } catch (Exception e) {
            log.error("", e);
            feedback.setText(e.getMessage());
        }
        return feedback.stop();
    }

}
